<template>
    
        <ul>
            <li class="item" v-for="item of letters" :ref="item" :key="item" 
            @click="HandleClick" 
            @touchstart.prevent="handleTouchStart"
            @touchmove="handleTouchMove"
            @touchend="handleTouchEnd"
            >
                {{item}}
            </li>
           
        </ul>
</template>

<style lang="stylus" scoped>
    @import "~styles/variable.styl";
    .list{
        position :absolute;
        right :.1rem;
        top:2rem;
        display :flex;
        flex-direction :column;
        justify-content :center;
        height :80%;
        .item{
            text-align :center;
            line-height :.44rem;
            font-weight :600;
            color:$bgColor
        }
    }
    
</style>

<script>
export default {
    name:"CityAlphabet",
    props:{
        cities:Object
    },
    data(){
        return {
            touchStatus:false
        }
    },
    computed:{
        letters(){
            const letters = [];
            for(let i in this.cities){
                letters.push(i)
            }
            return letters
        }
    },
    methods:{
        HandleClick(event){
            this.$emit("change",event.target.innerText)
        },
        handleTouchStart(){//
            this.touchStatus = true;
        },
        handleTouchMove(e){
            if(this.touchStatus){
                const startY = this.$refs["A"][0].offsetTop;
                const touchY = e.touches[0].clientY-134;
                const index = Math.floor((touchY - startY) / 20);
                if(index>= 0 && index<this.letters.length){
                    this.$emit("change",this.letters[index])
                }
                
            }

        },
        handleTouchEnd(){
            this.touchStatus = false
        }
    }
}
</script>


